// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

import iView from 'iview';
Vue.use(iView);
//网络请求
//import 'iview/dist/styles/iview.css'; // 使用 CSS
import '@/cmdb-less/cmdb.less';

// 导入插件
import colorPicker from './plugin/vue-color-picker'
// 注册插件
Vue.use(colorPicker)

import vuescroll from 'vue-scroll'
Vue.use(vuescroll)

import store from '@/store/AppStore.js';
import axios from 'axios'
axios.interceptors.request.use(
  config => {
  	console.log(store.getters.token);
    let token = store.getters.token;
    // 判断是否存在token，如果存在的话，则每个http header都加上token
    if (token) { 
      config.headers['Access-Token'] = token;
    }
    return config;
  },
  err => {
    return Promise.reject(err);
  });
  
  
//响应拦截器
axios.interceptors.response.use(
  response => {
    // if (response.data.token != 'undefined' && response.data.token != null) {
    //     localStorage.setItem('userTOKEN', response.token);
    // }
    
    if (response.data.rescode == 102) {
      router.push({
        name: 'Login'
      })
    }
    return response;
  },
  error => {
    return Promise.reject(error);
  });
Vue.config.productionTip = false


/* eslint-disable no-new */
const vue = new Vue({
	el: '#app',
	axios,
	store,
	router,
	template: '<App/>',
	components: {
		App
	}
})

String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");　　
}　　
String.prototype.ltrim = function() {
	return this.replace(/(^\s*)/g, "");　　
}　　
String.prototype.rtrim = function() {
	return this.replace(/(\s*$)/g, "");　　
}